﻿using System;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//para trabalhar com o banco de dados
using System.Data.SqlClient;
using System.Data;


/// <summary>
/// Summary description for Execute
/// </summary>
public class Execute
{
    //static string stConn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Nany\Documents\Visual Studio 2008\WebSites\GerenciadoServicos\App_Data\servicos.mdf;Integrated Security=True; Current Language = British;User Instance=True";
    //static string stConn = ConfigurationManager.ConnectionStrings["servicosConnectionString1"].ConnectionString;
    static string stConn = ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
        public static SqlConnection RetornaConexaoDB()
    {
        return new SqlConnection(stConn);
    }

    //executa a inclusão, exclusão e alteração
	public void executa(string e)
	{
        //try
        //{
            if (e != "")
            {
                //cria conexão
                SqlConnection connection = new SqlConnection(stConn);

                //abre conexão
                connection.Open();

                //cria um objeto para poder trabalhar com a conexao
                SqlCommand command = connection.CreateCommand();

                command.CommandText = e;

                //executa uma sql que nao retorna resultado
                command.ExecuteNonQuery();

                connection.Close();
            }
  }

    //pesquisar
    public DataTable Pesquisar(string e)
    {
        DataTable pessoa = new DataTable("pessoa");

        string consulta = e;

        SqlDataAdapter adpt = new SqlDataAdapter(consulta, stConn);

        adpt.Fill(pessoa);
        return pessoa;
        
    }

}
